# 高云工具路径 
# http://cdn.gowinsemi.com.cn/SUG100.pdf
# 硬件资料: https://wiki.sipeed.com/hardware/zh/tang/tang-nano-20k/nano-20k.html
# 板卡资料: https://dl.sipeed.com/shareURL/TANG/Nano_20K/1_Datasheet

GOWIN_BASE = G:/soft/Gowin/Gowin_V1.9.8.11_Education
GGW_SH = $(GOWIN_BASE)/IDE/bin/gw_sh 
GGW_IDE = $(GOWIN_BASE)/IDE/bin/gw_ide 
GPROGRAMMER_CLI = $(GOWIN_BASE)/Programmer/bin/programmer_cli

PRJ_BITSTREAM = $(shell bash tools/bitstream.sh)
VLOG = iverilog

# 工程配置和编译的 tcl 脚本 
PRJ_TCL = synth_system.tcl 




all:build program_sram

help:
	@echo "Example build:"
	@echo "  make build"
	@echo "  make sim_system"

build: clean 
	mkdir -p build
	cp ../App/Debug/firmware.hex build/
	cp *.cst build/
	# cp $(PRJ_TCL) build/
	bash tools/make_synth_tcl.sh *.gprj > build/synth_system.tcl 
	cp *.gprj build/
	cd build/ && $(GGW_SH) $(PRJ_TCL) 

sim:
	mkdir -p build
	$(VLOG) -o build/tb.vvp -y rtl tb.v 
	cd build && vvp tb.vvp && gtkwave tb.vcd 


program_sram:
	$(GPROGRAMMER_CLI) --scan-cables
	$(GPROGRAMMER_CLI) --device GW2AR-18C --run 2 --fsFile  $(PRJ_BITSTREAM)  


clean:
	rm -rf build/
